#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef struct
{
    char id[14];
    int score;
    int locat; //地区标记
    int rank1; //地区排名
    int rank2; //总排名
} nod_t;
bool cmp(nod_t nodl, nod_t nodr)
{
    if (nodl.score != nodr.score)return nodl.score > nodr.score;
    else return strcmp(nodl.id, nodr.id) < 0;
}
int main()
{
    int num;
    scanf("%d", &num);
    int cnt[100] = {0}; //记录各地区考生数目，没必要用数组，后面用不上该数据
    nod_t testee[30000];
    int i, j;
    int count = 0;
    int locat;
    int rank;
    for (i = 0; i < num; ++i)
    { //逐个地区的读取数据
        scanf("%d", cnt + i);
        locat = i + 1;
        for (j = 0; j < cnt[i]; ++j)
        { //依次读取考生信息，同时初始化学生结点
            scanf("%s %d", testee[count].id, &testee[count].score);
            testee[count].locat = locat;
            ++count; //统计总考生数
        }
        int tag = count - cnt[i];                //记录该区域第一个输入考生的下标
        sort(testee + tag, testee + count, cmp); //区域排序
        testee[tag].rank1 = rank = 1;
        for (j = 1; j < cnt[i]; ++j)
        { //记录区域排名
            ++rank;
            testee[tag + j].rank1 = rank;
            if (testee[tag + j - 1].score == testee[tag + j].score)
            { //分数相同排名相同
                testee[tag + j].rank1 = testee[tag + j - 1].rank1;
            }
        }
    }
    sort(testee, testee + count, cmp); //总排名
    rank = 1;
    testee->rank2=1;
    for (i = 1; i < count; ++i)
    {
        ++rank;
        testee[i].rank2 = rank;
        if (testee[i].score == testee[i - 1].score)
        {
            testee[i].rank2 = testee[i - 1].rank2;
        }
    }
    printf("%d\n", count);
    for (i = 0; i < count; ++i)
    {
        printf("%s %d %d %d\n", testee[i].id, testee[i].rank2, testee[i].locat, testee[i].rank1);
    }
}